<template>
  <div>
    <Row class="header" type="flex" justify="center">
      <Col span="24">
        <Icon class="icon" type="md-pie"/>
        <span class="title">柱状图</span>
      </Col>
    </Row>
    <br>
    <div id="TypesHistogramPie" :style="{ width: width + 'px', height: height + 'px'}"></div>
  </div>
</template>

<script>
import echarts from 'echarts'
// import mockData from './mockData'

export default {
  name: 'TypesCompanyHistogramEchart',
  data () {
    return {
      chartData: []
    }
  },
  props: {
    width: {
      type: Number,
      default: () => {
        return 300
      }
    },
    height: {
      type: Number,
      default: () => {
        return 200
      }
    }
  },
  mounted () {
    this.chart()
  },
  methods: {
    chart () {
      let option = {
        tooltip: {
          trigger: 'axis'
        },
        grid: {
          right: '1px',
          left: '30px',
          bottom: '10%',
          containLabel: true
        },
        legend: {
          textStyle: {
            fontSize: 16, // 字体大小
            color: '#ffffff'// 字体颜色
          },
          orient: 'vertical',
          left: 10,
          data: ['蒸发量', '降水量']
        },
        calculable: true,
        xAxis: [
          {
            axisLabel: {
              show: true,
              textStyle: {
                color: '#ffffff'
              }
            },
            type: 'category',
            data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']
          }
        ],
        yAxis: [
          {
            axisLabel: {
              textStyle: {
                color: '#ffffff'
              }
            },
            type: 'value'
          }
        ],
        series: [
          {
            color: ['#FFDB5C'],
            name: '蒸发量',
            type: 'bar',
            data: [2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3]
          },
          {
            color: ['#67E0E3'],
            name: '降水量',
            type: 'bar',
            data: [2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3]
          }
        ]
      }

      this.chartData.forEach(item => {
        option.dataset.source.push(item)
      })
      let myChart = echarts.init(document.getElementById('TypesHistogramPie'))
      myChart.setOption(option)
    }
  }
}
</script>

<style scoped>
  .header {
    margin-left: 10px;
    margin-top: 10px;
    height: 30px;
  }

  .icon {
    color: #d7f5ff;
    font-size: 28px;
    font-weight: 600;
    margin-right: 5px;
  }
  .title {
    color: #d7f5ff;
    font-size: 16px;
    font-weight: 600;
    line-height: 30px;
  }
</style>
